package com.cy.study.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cy.study.common.Response;
import com.cy.study.req.UserPageReq;
import com.cy.study.req.UserStatusChangeReq;
import com.cy.study.res.UserDetailRes;
import com.cy.study.res.UserPageRes;
import com.cy.study.service.UserInfoService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * 用户信息控制器
 */
@RequiredArgsConstructor
@RequestMapping("/userInfo")
@RestController
@CrossOrigin
@Slf4j
public class UserInfoController {

    private final UserInfoService userInfoService;

    /**
     * 用户列表
     * @param req
     * @return
     */
    @PostMapping("/userPage")
    public Response<Page<UserPageRes>> userPage(@RequestBody UserPageReq req){
        Page<UserPageRes> res = userInfoService.userPage(req);
        return Response.success(res);
    }

    /**
     * 用户信息详情
     * @param userId
     * @return
     */
    @GetMapping("/userDetail/{userId}")
    public Response<UserDetailRes> userDetail(@PathVariable Integer userId){
        UserDetailRes res = userInfoService.userDetail(userId);
        return Response.success(res);
    }

    /**
     * 切换用户状态
     * @param req
     * @return
     */
    @PostMapping("/changeStatus")
    public Response changeStatus(@RequestBody UserStatusChangeReq req){
        userInfoService.changeStatus(req);
        return Response.success();
    }

}
